package core.config;

import org.testng.Assert;

import core.ApplicationManager;
import core.helpers.PropertyLoaderHelper;

/**
 * Test Configurations
 */
public class Config
{

	// Servers
	public final static String SERVER_LOCAL = "local";
	public final static String SERVER_SAUCELABS = "saucelabs";
	// Locations
	public static final String LOCATION_ARG = "ARG";
	public static final String LOCATION_BRA = "BRA";
	public static final String LOCATION_GBR = "UK";
	public static final String LOCATION_USA = "US";
	public static final String LOCATION_AUS = "AUS";
	public static final String LOCATION_FRA = "FRA";
	public static final String LOCATION_AUT = "AUT";
	public static final String LOCATION_BEL = "BEL";
	public static final String LOCATION_CAN = "CAN";
	public static final String LOCATION_CHN = "CHN";
	public static final String LOCATION_CZE = "CZE";
	public static final String LOCATION_DNK = "DNK";
	public static final String LOCATION_DEU = "DEU";
	public static final String LOCATION_IND = "IND";
	public static final String LOCATION_INN = "INN";
	public static final String LOCATION_ITA = "ITA";
	public static final String LOCATION_JPN = "JPN";
	public static final String LOCATION_MYS = "MYS";
	public static final String LOCATION_MEX = "MEX";
	public static final String LOCATION_NLD = "NLD";
	public static final String LOCATION_NZL = "NZL";
	public static final String LOCATION_NOR = "NOR";
	public static final String LOCATION_PRT = "PRT";
	public static final String LOCATION_ZAF = "ZAF";
	public static final String LOCATION_ESP = "ESP";
	public static final String LOCATION_SWE = "SWE";
	public static final String LOCATION_CHE = "CHE";
	public static final String LOCATION_TUR = "TUR";
	public static final String LOCATION_FIN = "FIN";
	public static final String LOCATION_IRL = "IRL";
	public static final String LOCATION_RANDOM = "ANY";
	// Sikuli
	public final static String SIKULI_LOCATORS_PATH = "path";
	// WebDriver Waitings
	public static int WEBDRIVER_WAIT;
	public static Boolean WEBDRIVER_FLASH_ELEMENTS;
	public static Boolean WEBDRIVER_CAPTURE_SCREENSHOT;

	// Platforms
	public final String PLATFORM_WEB = "web";
	public final String PLATFORM_MOBILE = "mob";
	public final String PLATFORM_APP = "app";

	// Browsers
	public final String BROWSER_FIREFOX = "firefox";
	public final String BROWSER_CHROME = "chrome";
	public final String BROWSER_IEXPLORER = "iexplorer";
	public final String BROWSER_SAFARI = "safari";
	public final String BROWSER_IPAD = "ipad";
	public final String BROWSER_ANDROID = "android";
	public final String BROWSER_IPHONE = "iphone";

	// Browser Profiles
	public String BROWSER_FIREFOX_PROFILE;

	// Browser Versions
	public final String BROWSER_FF_VERSION = "27";
	public final String BROWSER_CH_VERSION = "32";
	public final String BROWSER_IE_VERSION = "10";
	public final String BROWSER_SF_VERSION = "6";
	public final String BROWSER_IPAD_VERSION = "6";
	public final String BROWSER_ANDROID_VERSION = "4.3";
	public final String BROWSER_IPHONE_VERSION = "4.0";
	// OS
	public final String OS_WIN_7 = "win_7";
	public final String OS_WIN_8 = "win_8";
	public final String OS_ANDROID = "android";
	// Screen Resolutions
	public final String SCREEN_RESOLUTION_1920x1200 = "1920x1200";
	public final String SCREEN_RESOLUTION_1440x900 = "1440x900";
	public final String SCREEN_RESOLUTION_1280x1024 = "1280x1024";
	public final String SCREEN_RESOLUTION_1024x768 = "1024x768";

	// ApplicationManager instance
	protected final ApplicationManager manager;
	// Projects
	public String PROJECT_PHOENIX = "phoenix";
	public String PROJECT_PILOT = "pilot";
	// Proxies
	public String PROXY_GBR = "p-uk1.biscience.com:80";
	public String PROXY_USA = "p-us1.biscience.com:80";
	public String PROXY_AUS = "p-au1.biscience.com:80";
	public String PROXY_BRA = "p-br1.biscience.com:80";
	public String PROXY_CAN = "p-ca2.biscience.com:80";
	public String PROXY_MEX = "p-mx1.biscience.com:80";
	public String PROXY_FIN = "p-fi1.biscience.com:80";
	public String PROXY_IND = "p-in1.biscience.com:80";
	public String PROXY_IRL = "p-ie1.biscience.com:80";
	public String PROXY_NZL = "p-nz1.biscience.com:80";
	public String PROXY_NLD = "p-nl1.biscience.com:80";
	public String PROXY_SWE = "p-se1.biscience.com:80";
	public String PROXY_NOR = "p-no1.biscience.com:80";
	public String PROXY_ITA = "p-it1.biscience.com:80";
	public String PROXY_ESP = "p-es1.biscience.com:80";
	public String PROXY_FRA = "p-fr1.biscience.com:80";
	// Builds
	public static String BUILD_LIVE = "live";
	public static String BUILD_REL = "rel";
	public String BUILD_TRUNK = "trunk";
	public static String BUILD;

	// Screen Recorder
	public boolean SCREENLOGGER = false;
	public String SCREENLOGGER_FOLDER;
	// URL to HAR storage
	public String HAR_STORAGE_URL;
	// HAR reports
	public String HAR_REPORTS_PATH;

	// Proxy
	public static Boolean PROXY_AUTH;
	public String PROXY_USERNAME;
	public String PROXY_PASSWORD;
	// Data Base data
	public String DB_HOST;
	public String DB_PORT;
	public String DB_NAME;
	public String DB_USER;
	public String DB_PASSWORD;

	public String HTTP_USERNAME;
	public String HTTP_PASSWORD;

	// Mail
	public String MAIL_GATEWAY;
	public String MAIL_USER;
	public String MAIL_PASSWORD;
	public String MAIL_HTML_PATH;
	public static String MAIL_DELAY;

	// Settings for outgoing server
	public String SMTP_HOST;
	public String SMTP_PORT;
	public String SMTP_USER;
	public String SMTP_PASSWORD;

	/**
	 * APPIUM SETTINGS *
	 */
	public String APPIUM_DEVICE = "any";
	public String APPIUM_BROWSER;
	public String APPIUM_PATH;

	public String APPIUM_CHROMEDRIVER;
	public String APPIUM_LOG;
	public String APPIUM_LOGLEVEL;
	public String APPIUM_COMMANDTIMEOUT;
	public String APP_ACTIVITY_BN;
	public String ANDROID_PACKAGE_BN;
	public String APP_ACTIVITY_FLIRT;
	public String ANDROID_PACKAGE_FLIRT;
	public String APP_ACTIVITY_WB;
	public String ANDROID_PACKAGE_WB;
	public String APP_ACTIVITY_CL;
	public String ANDROID_PACKAGE_CL;

	/**
	 * Initializes Config
	 * @param p_manager ApplicationManager instance
	 */
	public Config(ApplicationManager p_manager)
	{
		manager = p_manager;
	}

	/**
	 * Loads a configuration file
	 * @param p_pathToFile Path to configuration file
	 * @return PropertyLoaderHelper instance
	 */
	protected PropertyLoaderHelper loadResFile(String p_pathToFile)
	{
		Assert.assertTrue(manager.file().isFileResExist(p_pathToFile), "Configuration file not found: " + p_pathToFile);

		return new PropertyLoaderHelper(manager, p_pathToFile);
	}

	/**
	 * Loads a configuration file
	 * @param p_pathToFile Path to configuration file
	 * @return PropertyLoaderHelper instance
	 */
	protected PropertyLoaderHelper loadFile(String p_pathToFile)
	{
		Assert.assertTrue(manager.file().isFileExist(p_pathToFile), "Configuration file not found: " + p_pathToFile);

		return new PropertyLoaderHelper(manager, p_pathToFile);
	}

	/**
	 * Loads a configuration file
	 * @param p_pathToFile Path to configuration file
	 * @return PropertyLoaderHelper instance
	 */
	protected PropertyLoaderHelper loadExtFile(String p_pathToFile)
	{
		if (manager.file().isFileExist(p_pathToFile))
		{
			return new PropertyLoaderHelper(manager, p_pathToFile);
		}
		return null;
	}
}
